package com.org.cloud.lg.controller;

import com.org.cloud.lg.api.RoleService;
import com.org.cloud.lg.dto.RoleDto;
import com.org.cloud.lg.model.BaseController;
import com.org.cloud.lg.model.PageDto;
import com.org.cloud.lg.utils.ApiResult;
import org.springframework.data.domain.Page;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author DL
 * @since 2018-03-19
 */
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<RoleService> {
	private String prefix="system/role/";


	@RequestMapping("page")
	public PageDto<RoleDto> page(@RequestBody PageDto<RoleDto> roleDto){
		return service.listPage(roleDto);
	}
	

	@PostMapping("/save")
	public boolean save(@RequestBody  RoleDto role){
		return service.insert(role);
	}
	
	@PostMapping("/update")
	public boolean update(@RequestBody  RoleDto role, BindingResult bindingResult){
		return service.updateByPk(role);
	}
	
	@DeleteMapping("/delete")
	public ApiResult deleteRow(@RequestParam  String id){
		return service.deleteById(id);
	}

	/** 
	* @Description: 添加用户时需要选择用户角色此处查询所有角色
	* @param @return  
	* @return List<Role> 
	* @throws 
	*/ 
	@RequestMapping("/selectAllRoles")
	public List<RoleDto> selectAllRoles(){
		return service.selectAllRoles();
	}
	
	
//	@PostMapping("/checkIsExist")
//	public boolean checkIsExist(Role roleEntity){
//		Long roleId=roleEntity.getRoleId();
//		roleEntity.setRoleId(null);
//		QueryWrapper<Role> query = new QueryWrapper<Role>(roleEntity);
//		Role role=service.getOne(query);
//		if(role!=null){
//		    if(roleId!=null){//编辑时
//                  if(role.getRoleId().intValue()==roleId.intValue()){
//                     return true;
//                  }else{
//                      return false;
//                  }
//            }else{
//                return false;
//            }
//		}else{
//			return true;
//		}
//	}

}
